<!-- 新增/编辑 组织机构 -->
<template>
  <a-modal v-model:visible="visible" width="45vw" title="作废订单" unmount-on-close>
    <div class="tips-text"
      >订单作废后，系统不能自动恢复，同时对应订单产生费用也会作废，不进行统计；状态为待生成、生成失败和未发起的合同也将会无效，请确认是否作废当前订单？</div
    >
    <page-form class="page-form" :model="form" layout="vertical" ref="formRef">
      <page-form-item field="invalidRemark" label="作废备注" size="1" :rules="{ required: false, message: '请输入作废备注' }">
        <i-textarea v-model="form.invalidRemark" />
      </page-form-item>
    </page-form>
    <template #footer>
      <a-space>
        <a-button @click="onCancel">关闭</a-button>
        <a-button type="primary" @click="onConfirm" :loading="okLoading">确认</a-button>
      </a-space>
    </template>
  </a-modal>
</template>

<script setup>
  import { ref } from 'vue'
  import { invalidOrder } from '@/api/order/czsOrder'
  import { Notification } from '@arco-design/web-vue'
  import iTextarea from '@/views/order/long-order/components/i-textarea.vue'
  const visible = ref(false)
  const form = ref({})
  const emit = defineEmits(['ok'])
  const open = (record) => {
    visible.value = true
    form.value = {
      id: record.id,
    }
  }
  const okLoading = ref(false)
  const onCancel = () => {
    okLoading.value = false
    visible.value = false
  }
  const formRef = ref()
  const onConfirm = () => {
    formRef.value.validate((error) => {
      if (!error) {
        okLoading.value = true
        const param = {
          ...form.value,
        }
        invalidOrder(param)
          .then(() => {
            Notification.success('作废成功')
            visible.value = false
            emit('ok')
          })
          .finally(() => {
            okLoading.value = false
          })
      }
    })
  }
  defineExpose({
    open,
  })
</script>

<style lang="less" scoped>
  .page-form {
    min-height: 300px;
    overflow-x: hidden;
  }
  .tips-text {
    height: 20px;
    font-size: 14px;
    color: #165dff;
    line-height: 20px;
    text-align: center;
    margin-bottom: 20px;
  }
</style>
